package com.yiwei.zhh.api.requestInfo;

import android.content.Context;

import com.yiwei.zhh.activity.BaseActivity;
import com.yiwei.zhh.activity.BaseLiMuActivity;
import com.yiwei.zhh.api.contract.BaseContract;
import com.yiwei.zhh.fragment.BaseFragment;
import com.yiwei.zhh.util.JsonUtil;

/**
 * Created by Administrator on 2017/5/14.
 */

public class BaseRequest<T extends BaseContract.BaseView> implements BaseContract.BasePresenter<T> {

    protected T mView;
    protected Context BaseContext;
    protected final String networkFail="网络连接失败";

    public Context getContext() {
        if (mView instanceof BaseActivity) {
            BaseContext = ((BaseActivity) mView);
        }else if(mView instanceof BaseLiMuActivity){
            BaseContext = ((BaseLiMuActivity) mView);
        } else if (mView instanceof BaseFragment) {
            BaseContext = ((BaseFragment) mView).getContext();
        }
        if (BaseContext == null) {
            return null;
        }
        return BaseContext;
    }

    protected String  toJson(Object obj){
     return  JsonUtil.toJson(obj);
    }

    @Override
    public void attachView(T view) {
        this.mView = view;
        getContext();
    }

    @Override
    public void detachView() {
        this.mView = null;
        BaseContext = null;
    }
}
